package cn.edu.cdut.controller;

import cn.edu.cdut.dto.MyRes;
import cn.edu.cdut.dto.PasswordChange;
import cn.edu.cdut.service.ChangePassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

/**
 * Author  kobe
 * Created on 2017-06-26-22:24
 */
@RestController
public class ChangePassController {

        @Autowired
        private ChangePassService changePassService;

        @PostMapping("/changePassword")
        public MyRes changePassword(@RequestBody PasswordChange passwordChange, BindingResult bindingResult) {
                if (bindingResult.hasErrors()) {
                        return new MyRes(201, "未知错误！", null);
                }
                return changePassService.changePassword(passwordChange);
        }

        @GetMapping("/resetPassword")
        public MyRes resetPassword(@RequestParam String userId) {
                return changePassService.resetPassword(userId);
        }

}
